<?php
include_once('SEGConexao.php');

class SEGMysql extends SEGConexao { 
	protected $index;    // indice do vetor $result   
	protected $intquery; // int representando o resultado da query   
	public $result;      // fetch_array de $intquery 
	public $count;       // qtde de linhas encontradas 	
	public $coluna;
	public $idcolu;

	public function SEGMysql ($host=false, $db=false) {		
		$this -> SEGConexao($host,$db);
	}
	//****************************** QUERY 
	public function query ($query_str) { 
		$this->first(); 

		$this->intquery = mysql_query($query_str,$this->conect); 
		if (!$this->intquery) { 
			$this->error = mysql_error(); 
			$this->status = false; 
			return false; 
		} 
		else { 
			if (strtolower(substr($query_str,0,6))=="select") { 
				$this->result = mysql_fetch_array($this->intquery); 
				$this->count = mysql_num_rows($this->intquery); 
			} 
			$this->error = ""; 
			$this->status = true; 
			return true; 
		} 
	} 

	//****************************** MOVIMENTACAO 
	public function seek ($id) { 
		if (!mysql_data_seek($this->intquery, $id)) { 
			$this->error = mysql_error(); 
			$this->status = false; 
			return false; 
		} 
		else { 
			$this->result = mysql_fetch_array($this->intquery);	  
			$this->error = ""; 
			$this->index = $id; 
			return true; 
		} 
	} 
	
	public function first () { 
		if ($this->index!=0) { 
			$this->seek(0); 
			$this->index=0; 
		} 
	} 
	
	public function previous () { 
		if ($this->index-1>0) { 
			$this->seek($this->index-1); 
		} 
	} 
	
	public function next () { 
		if ($this->index+1<$this->count) { 
			$this->seek($this->index+1); 
		} 
	} 
	
	public function last () { 
		if ($this->index!=$this->count) { 
			$this->seek($this->count); 
			$this->index=$this->count; 
		} 
	} 

	//****************************** ID DO ULTIMO REGISTRO INSERIDO 
	public function lastId() { 
		return mysql_insert_id($this->conect); 
	} 
} 
?>